package com.quanyan.video.repository;

import com.quanyan.common.exception.BizException;
import com.quanyan.common.vo.Video;
import com.quanyan.video.emun.VideoErrorEnum;
import com.quanyan.video.entity.Bucket;
import com.quanyan.video.entity.BucketExample;
import com.quanyan.video.mapper.BucketMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by wmb on 2016/6/27.
 */
@Repository
public class BucketRepository {
    @Autowired
    private BucketMapper bucketMapper;
    public Bucket selectByProjectAndName(Integer id, String bucketName) {
        BucketExample bucketExample=new BucketExample();
        bucketExample.createCriteria().andProjectIdEqualTo(id).andNameEqualTo(bucketName);
        List<Bucket> bucketList=bucketMapper.selectByExample(bucketExample);
        if(bucketList.isEmpty()){
            throw new BizException(VideoErrorEnum.BUCKET_NOT_EXIST);
        }else{
            return bucketList.get(0);
        }

    }

    public Integer insertSelective(Bucket bucket) {
        bucketMapper.insertSelective(bucket);
        return bucket.getId();
    }
}
